package com.example.mapper;

import com.example.pojo.ArticleQueryParam;
import com.example.pojo.Articles;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface ArticlesMapper {

    List<Articles> list(ArticleQueryParam studentQueryParam);

@Insert("insert into blog_system.articles(title,content,category_id,author,publish_date,create_time,update_time,author_id,category_name)" +
        "values(#{title},#{content},#{categoryId},#{author},#{publishDate},#{createTime},#{updateTime},#{authorId},#{categoryName})")
    void add(Articles student);
@Select("select * from blog_system.articles where id=#{id}")
Articles getbyid(Integer id);
    @Update("update blog_system.articles set title=#{title},content=#{content},category_id=#{categoryId},author=#{author},publish_date=#{publishDate},author_id=#{authorId},category_name=#{categoryName}," +
            "update_time=#{updateTime} where id=#{id}")
    void updateclazz(Articles student);

    void deleteByIds(List<Integer> ids);
    @Update("update student set violation_score=violation_score+#{score} ,violation_count=violation_count+1 ,update_time=now() where id=#{id}  ")
    void updata(Integer id, Integer score);


    List<Map<String, Object>> coutstudentCountData();

    void deleteByAuthorIds(List<Integer> ids);

    void insertBatch(List<Articles> exprList);

    void showBatch(List<Articles> exprList);
@Select("select title, category_name,publish_date from blog_system.articles a,blog_system.article_categories ac where author_id=#{id} and category_id =ac.id")
    List<Articles> showByauthorId(Integer id);
@Select("select * from blog_system.articles order by publish_date desc ")
    List<Articles> list2(ArticleQueryParam studentQueryParam);
}

